<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体育与健康课程管理系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/main.css"/>
    <link href="${pageContext.request.contextPath}/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/public/js/layer/layer.js"></script>
	<script src="${pageContext.request.contextPath}/public/bootstrap/js/bootstrap.min.js"></script>
</head>
<style>
.addtab
{
    float:left;
/*    margin-top:10px;*/
    margin-left: 90px;
}
.addtab tr
{
    float:left;
    margin-top: 20px;
    width:300px;
}
.addtab th
{
    width:90px;
    font-size: 15px;
    font-family: '微软雅黑';
    color:#000;
    float:left;
    font-weight:normal;
}
.addtab input
{
    border-radius: 5px;
    float:left;
    height:30px;
}

.addtab select
{
    border-radius: 5px;
    float:left;
    height:30px;
}
.btn12
{
    width:160px;
    height:40px;
    letter-spacing: 10px;
    font-size: 16px;
  
}
.require-red {
    color: #f60;
    font-family: serif;
    margin-right: 3px;
}

</style>
<body>
<p style="margin-top:15px;margin-left:40px; font-size:16px; border-left:3px #006dcc solid; padding-left:5px">查看学生信息</p>
<div class="container clearfix" style="width:100%">
    <div class="main-wrap">
        <div class="search-wrap">
        	<div class="search-content">
        	<form action="${pageContext.request.contextPath}/jwc/studentinfo/searchstudent.action" method="post">
        	 <table class="search-tab">
        	 	<th width="90" style="font-size:16px">学生学号:</th>
        	 	<td><input type="text" class="common-text" style="height:32px" placeholder="学生学号" name="userStudentInfoNum" /></td>
        	 	 <td><button type="submit" class="btn btn-primary" onclick="">搜索</button></td>
        	 </form>
        	 
        	 <form action="${pageContext.request.contextPath}/jwc/studentinfo/selectstdent.action" method="post">
        	 	<th width="150px" style="font-size:16px">选择分类:</th>
        	 	<td>
        	 	  <select name="userStudentInfoYear" style="width:120px;height:30px;border-radius:2%">
        	 	  <%if(session.getAttribute("userStudentInfoYear")!=null&&(int)session.getAttribute("userStudentInfoYear")!=0){%>
        	 		  <option value="<%=session.getAttribute("userStudentInfoYear") %>"><%=session.getAttribute("userStudentInfoYear") %></option><%} %>
         			<option value="0">全部年级</option>
                    <c:forEach items="${year }" var="x">
                     <option value="${x}">${x}级</option>
                    </c:forEach>
                  </select>
        	 	<select name="userStudentInfoCollege" style="width:120px;height:30px;border-radius:2%">
         		<%if(session.getAttribute("userStudentInfoCollege")!=null&&!session.getAttribute("userStudentInfoCollege").equals("0")){%>
        	 		  <option value="<%=session.getAttribute("userStudentInfoCollege") %>"><%=session.getAttribute("userStudentInfoCollege") %></option><%} %>
         			<option value="0">全部学院</option>
                    <c:forEach items="${college }" var="x">
                     <option value="${x}">${x }</option>
                    </c:forEach>
                  </select>
				</td>
				<td><input class="btn btn-primary btn2" name="sub" value="查询" type="submit"></td>
        	 </form>
        	 
        	<form enctype="multipart/form-data" id="myform">
        	 	<th width="150px" style="font-size:16px">导入学生信息:</th>
        	 	<td><input type="file" name="file" /></td>
        	 	 <td><button type="button" id="noclick" class="btn btn-primary" onclick="upload()">导入学生信息</button></td>
        		<td><button type="button" class="btn btn-success" onclick="window.location.href='${pageContext.request.contextPath}/public/moban/student.xlsx'">下载模板</button></td>
        	 </form>
        	 
        	 	</table>
        	</div>
        </div>
        <div class="result-wrap" >
               <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:;" data-toggle="modal" data-target="#myModal" ><i class="icon-font"></i>添加学生</a>
                    </div>
                </div>
                <div class="result-content" id="app" >
                    <table class="result-tab" width="100%" id="addto">
                        <tr>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>入学时间</th>
                            <th>所在学院</th>
                            <th>行政班级</th>
                            <th>所在专业</th>
                            <th>操作</th>
                        </tr>
                      <c:forEach items="${pageinfo.list}" var="v">
                        <tr >
                            <td>${v.userStudentInfoNum}</td>
                           	<td>${v.userStudentInfoName }</td>
                         	<td>${v.userStudentInfoSex }</td>
                         	<td>${v.userStudentInfoYear }</td>
                         	<td>${v.userStudentInfoCollege }</td>
                         	<td>${v.userStudentInfoFormalclass }</td>
                         	<td>${v.userStudentInfoMajor }</td>
                            <td>
                            <button type="button" class="btn btn-danger" onclick="dele(${v.userStudentInfoId})">删除</button>
                            </tr>
  					</c:forEach>
                    </table>
                </div>
                </div>
               <div class="row">
				<div class="col-md-3">当前${pageinfo.getPageNum() }页,总${pageinfo.getPages() }
				页,总${pageinfo.getTotal()}条记录</div>
                <div class="col-md-9">
				<nav aria-label="Page navigation">
				<%if(session.getAttribute("userStudentInfoYear") == null && session.getAttribute("userStudentInfoCollege") == null){ %>
				<ul class="pagination">
					<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/student.action?pn=1">首页</a></li>
					<c:if test="${pageInfo.hasPreviousPage }">
						<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/student.action?pn=${pageInfo.pageNum-1}"
							aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
						</a></li>
					</c:if>


					<c:forEach items="${pageinfo.navigatepageNums }" var="page_Num">
						<c:if test="${page_Num == pageinfo.pageNum }">
							<li class="active"><a href="#">${page_Num }</a></li>
						</c:if>
						<c:if test="${page_Num != pageinfo.pageNum }">
							<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/student.action?pn=${page_Num }">${page_Num }</a></li>
						</c:if>

					</c:forEach>
					<c:if test="${pageinfo.hasNextPage }">
						<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/student.action?pn=${pageinfo.pageNum+1 }"
							aria-label="Next"> <span aria-hidden="true">&raquo;</span>
						</a></li>
					</c:if>
					<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/student.action?pn=${pageinfo.pages}">末页</a></li>
				</ul>
				<%} else{ %>
					<ul class="pagination">
					<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/selectstdent.action?pn=1&userStudentInfoYear=<%=session.getAttribute("userStudentInfoYear") %>&userStudentInfoCollege=<%=session.getAttribute("userStudentInfoCollege") %>">首页</a></li>
					<c:if test="${pageInfo.hasPreviousPage }">
						<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/selectstdent.action?pn=${pageInfo.pageNum-1}&userStudentInfoYear=<%=session.getAttribute("userStudentInfoYear") %>&userStudentInfoCollege=<%=session.getAttribute("userStudentInfoCollege") %>"
							aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
						</a></li>
					</c:if>


					<c:forEach items="${pageinfo.navigatepageNums }" var="page_Num">
						<c:if test="${page_Num == pageinfo.pageNum }">
							<li class="active"><a href="#">${page_Num }</a></li>
						</c:if>
						<c:if test="${page_Num != pageinfo.pageNum }">
							<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/selectstdent.action?pn=${page_Num }&userStudentInfoYear=<%=session.getAttribute("userStudentInfoYear") %>&userStudentInfoCollege=<%=session.getAttribute("userStudentInfoCollege") %>">${page_Num }</a></li>
						</c:if>

					</c:forEach>
					<c:if test="${pageinfo.hasNextPage }">
						<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/selectstdent.action?pn=${pageinfo.pageNum+1 }&userStudentInfoYear=<%=session.getAttribute("userStudentInfoYear") %>&userStudentInfoCollege=<%=session.getAttribute("userStudentInfoCollege") %>"
							aria-label="Next"> <span aria-hidden="true">&raquo;</span>
						</a></li>
					</c:if>
					<li><a href="${pageContext.request.contextPath}/jwc/studentinfo/selectstdent.action?pn=${pageinfo.pages}&userStudentInfoYear=<%=session.getAttribute("userStudentInfoYear") %>&userStudentInfoCollege=<%=session.getAttribute("userStudentInfoCollege") %>">末页</a></li>
				</ul>
				
				<% 	session.removeAttribute("userStudentInfoYear");
					session.removeAttribute("userStudentInfoCollege");
				} %>
				</nav>
			</div>
			</div>

    </div>
</div>

<div  class="modal fade bs-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header" >
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
				</button>
				<h4 class="modal-title" id="myModalLabel">
					添加学生
				</h4>
			</div>
			<div >
			<form id="mystudent">
				<table  class="addtab" id="cont">
				<tr><th><i class="require-red">*</i>学号：</th><td><input  name='userStudentInfoNum' type="text"  placeholder="学号"></td></tr>
				<tr><th><i class="require-red">*</i>姓名：</th><td><input  name='userStudentInfoName' type="text"  placeholder="姓名"></td></tr>
				<tr><th><i class="require-red">*</i>性别：</th>  
				        <td><select name="userStudentInfoSex">
				          <option value="男">男</option>
				          <option value="女">女</option>
				     	</select>                         	
				       </td>
				</tr>
				<tr><th><i class="require-red">*</i>入学时间：</th><td><input  name='userStudentInfoYear' type="text"  placeholder="入学时间 （例如：2015）" onkeyup="value=value.replace(/[^\d.]/g,'')"></td></tr>
				<tr><th><i class="require-red">*</i>所在学院：</th>  
				        <td><select name="userStudentInfoCollege">
		                    <c:forEach items="${college }" var="x">
		                     <option value="${x}">${x }</option>
		                    </c:forEach>
				     	</select>                         	
				       </td>
				</tr>
				<tr><th><i class="require-red">*</i>行政班级：</th><td><input  name='userStudentInfoFormalclass' type="text"  placeholder="行政班级"></td></tr>				
				<tr><th><i class="require-red">*</i>所在专业：</th>  
				        <td><select name="userStudentInfoMajor">
		                    <c:forEach items="${major }" var="x">
		                     <option value="${x}">${x }</option>
		                    </c:forEach>
				     	</select>                         	
				       </td>
				</tr>				
				</table>
		</form>
		</div>
			<div class="modal-footer" id="foot" style="border-top:none;">
				<button type="button" class="btn btn-default" data-dismiss="modal">
					关闭
				</button>
				<button type="button" class="btn btn-primary" onclick="add()">
					提交
				</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</body>
<script>
   $(function () { $('#myModal').modal('hide')});
</script>
<script type="text/javascript">
$(function () { $('#myModal').on('hide.bs.modal', function () { })
});
</script>	
<script type="text/javascript">
function dele(id)
{
	var r=confirm("确定要删除？");
	if(r==true){
		$.get("${pageContext.request.contextPath}/jwc/studentinfo/deletestudent.action",{id:id},function(returndata){
			if(returndata.code==1)
	            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
	                location.reload(); 
	              });
			else
				layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
		});
	}
}

function add()
{

	var userStudentInfoNum=$("input[name=userStudentInfoNum]");
	var userStudentInfoName=$("input[name=userStudentInfoName]");
	var userStudentInfoYear=$("input[name=userStudentInfoYear]");
	var userStudentInfoFormalclass=$("input[name=userStudentInfoFormalclass]");
	if(userStudentInfoNum.val()=="")
	{
        layer.msg('学号不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        userStudentInfoNum.focus();
        return ;		
	}
	if(userStudentInfoName.val()=="")
	{
        layer.msg('姓名不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        userStudentInfoName.focus();
        return ;		
	}
	if(userStudentInfoYear.val()=="")
	{
        layer.msg('入学时间不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        userStudentInfoYear.focus();
        return ;		
	}
	if(userStudentInfoFormalclass.val()=="")
	{
        layer.msg('行政班级不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        userStudentInfoFormalclass.focus();
        return ;		
	}
    var formData = new FormData($("#mystudent")[0]);//获取表单数据     
    $.ajax({
         url: "${pageContext.request.contextPath}/jwc/studentinfo/insert.action",//提交地址
         type: 'POST',
         data: formData,
         async: true,
         cache: false,
         processData: false,
         contentType: false,
         success: function (returndata) {
          if(returndata.code==1){
        	  $('#myModal').modal('hide');
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
              location.reload(); 
            });
          }
          else
          layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
         },
         error: function (returndata) {
          layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});
     }
    });   
}

function upload()
{
	$("#noclick").attr('disabled',true);
	layer.load(0,{ offset: ['15px', '40%'], icon:5});
	 var formData = new FormData($("#myform")[0]);//获取表单数据        
     $.ajax({
          url: "${pageContext.request.contextPath}/jwc/studentinfo/upload.action",//提交地址
          type: 'POST',
          data: formData,
          async: true,
          cache: false,
          contentType: false,
          processData: false,
          success: function (returndata) {
           if(returndata.code==1){
        	   layer.closeAll('loading');
               layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:2000},function(){
                   location.reload(); 
                 });
               $("#noclick").removeAttr('disabled'); 
           }
           else{
        	   $("#noclick").removeAttr('disabled'); 
        	   layer.closeAll('loading');
           	layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});    
           }
          },
          error: function (returndata) {
           layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

      }
     });   
	
	}
</script>
</html>